<template>
<table>
    <tr>
        <td>理财名称</td>
        <td>{{ data.Fname }}</td>
    </tr>
    <tr>
        <td>年收益</td>
        <td>{{ data.FARY }}</td>
    </tr>
    <tr>
        <td>利息</td>
        <td>{{ data.FIname }}%</td>
    </tr>
    <tr>
        <td>最低金额</td>
        <td>{{ data.Fminmoney.toFixed(2) }}CNY</td>
    </tr>
    <tr>
        <td>理财人次</td>
        <td>{{ data.Fnum }}</td>
    </tr>
    <tr>
        <td>风险等级</td>
        <td>{{ data.Flevel==1?"低风险":data.Flevel==2?"中风险":"高风险" }}</td>
    </tr>
    <tr>
        <td>投资金额</td>
        <td><input type="text" v-model="UFmoney"></td>
    </tr>
    <tr>
        <td colspan="2"><button @click="Add">投资</button></td>
    </tr>
</table>
</template>
<script setup lang="ts">
import axios from 'axios';
import {ref,onMounted} from 'vue'
import {useRoute} from 'vue-router'
import { useUserStore } from '../../Store/Index';
const userStore=useUserStore()
const route=useRoute()
const UFmoney=ref(0)
const data=ref({
    Fname:'',
    Fid:0,
    FARY:0,
    Fnum:0,
    FIname:'',
    Fminmoney:0,
    Flevel:0,
})
onMounted(()=>{
    Show()
})
const Show=()=>{
    axios.get("https://localhost:44396/api/Finan/ShowFid",
        {
            params:{
                Fid:route.query.Fid
            }
        }
    ).then(res=>{
        data.value=res.data[0]
        console.log(res.data[0])
    }).catch(err=>{
        console.log(err)
    })
}
const Add=()=>{
    if(UFmoney.value<data.value.Fminmoney){
        alert("投资金额不能小于最低金额")
        return
    }
    axios.get("https://localhost:44396/api/Finan/AddUFmoney",
        {
            params:{
                
                Fid:route.query.Fid,
                Uid:userStore.Uid,
                UFmoney:UFmoney.value,
            }
        }
    ).then(res=>{
        if(res.data>0){
            alert("投资成功")
        }else{
            alert("投资失败")
        }
    }).catch(err=>{
        console.log(err)
    })
}

</script>